package com.banana.manager.forest.service.impl.info;

import com.banana.manager.forest.dao.userandinfo.IMiceDao;
import com.banana.manager.forest.entity.info.MiceBean;
import com.banana.manager.forest.service.iinfo.IMiceService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class MiceServiceImpl implements IMiceService {

    @Resource
    private IMiceDao miceDao;

    @Override
    public MiceBean addNewMice(MiceBean miceBean) {
        miceDao.insert(miceBean);
        return miceDao.selectById(miceBean.getMiceId());
    }

    @Override
    public MiceBean findOneById(Integer id) {
        return miceDao.selectById(id);
    }

    @Override
    public PageInfo<MiceBean> findBlurByPage(Integer page, String miceName) {
        QueryWrapper<MiceBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("mice_name","%"+miceName+"%");
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(miceDao.selectList(queryWrapper));
    }
}
